package mo.tags.stack;

import java.util.Stack;

public class L150 {

    public int evalRPN(String[] tokens) {
        Stack<Integer> numbers = new Stack<>();
        for (String token : tokens) {
            if (token.equals("+") || token.equals("-") || token.equals("*") || token.equals("/")) {
                int num2 = numbers.pop();
                int num1 = numbers.pop();
                switch (token) {
                    case "+":
                        numbers.push(num1+num2);
                        break;
                    case "-":
                        numbers.push(num1-num2);
                        break;
                    case "*":
                        numbers.push(num1*num2);
                        break;
                    case "/":
                        numbers.push(num1/num2);
                        break;
                }
            } else {
                numbers.push(Integer.parseInt(token));
            }
        }
        return numbers.pop();
    }

    public static void main(String[] args) {
        L150 test = new L150();
        System.out.println(test.evalRPN(new String[]{"10","6","9","3","+","-11","*","/","*","17","+","5","+"}));
    }

}
